﻿using System;
using System.Web.Routing;

namespace Smarly.Web.ActionFilters
{
	public class BookStatisticAttribute : Attribute, IStatisticAttribute
	{
		private readonly string _routeElement;

		public BookStatisticAttribute(string routeElement)
		{
			_routeElement = routeElement;
		}


		public string Update(RouteValueDictionary values)
		{
			string result = null;
			if (values.ContainsKey(_routeElement))
			{
				object value = values[_routeElement];
				if (value != null)
					result = "[dbo].[Text_BookStatistic_Insert] @url='/"+ value + "'";
			}
			else
			{
				throw new Exception();
			}
			return result;
		}
	}

	public interface IStatisticAttribute
	{
		string Update(RouteValueDictionary values);
	}
}